$(function () {
    $("#backPage").load("/html/backPage.html");
})
// 查询所有调组记录
function findAll() {
    let data = {
        key: $("#selectKey").val(),
        startTime: $("#startTime").val(),
        endTime: $("#endTime").val(),
        pageNum: $("#pageNum").val(),
        pageSize: $("#pageSize").val()
    };
    let result = jsonGetValue("/stu/teamInfo/getSelectList", data);
    console.log(result);
    setAllData(result.data.list);
    $("#total").html(result.data.count);
}
function setAllData(data) {
    let html = "";
    for (let i=0; i<data.length;i++) {
        html += "<tr>\n" +
            '        <td><input type="checkbox" name="checkOne" value="' + data[i].id + '"></td>\n' +
            "        <td>"+ data[i].id +"</td>\n" +
            "        <td>"+ data[i].userCode +"</td>\n" +
            "        <td>"+ data[i].name +"</td>\n" +
            "        <td>"+ (data[i].oldTeamCode == 'all'?"暂无":data[i].oldTeamCode)+"</td>\n" +
            "        <td>"+ (data[i].newTeamCode == 'all'?"暂无":data[i].newTeamCode) +"</td>\n" +
            "        <td>"+ data[i].createTime +"</td>\n";
        html += "    <td>\n" +
            "            <div onclick='del(" + data[i].id +")' title='删除'>" +
            '            <a href="#del-modal-box" style="text-decoration:none;">' +
            '            <i class="iconfont icon-del">&#xe60b;</i></a></div>\n' +
            "        </td>\n" +
            "    </tr>";
    }

    $("#tbody").html(html)
    $("#tbody > tr > td").css({"vertical-align":"middle"})
    $("#tbody > tr > td:last-child").css({"display": "flex","justify-content": "flex-start"})
    $("#tbody > tr > td:last-child > div").css({"cursor": "pointer"})
    $("#tbody > tr > td:last-child > div").css({"margin-right":"10px"})
    myCheckAO();
}

// 根据id获取调组信息
function getTransferTeamInfoById(id) {
    let data = {id:id}
    let result = jsonGetValue("/stu/teamInfo/getTeamInfoById", data);
    console.log(result);
    setTransferTeamInfoDataById(result.data.data);
}

// 给删除模态框赋值
function setTransferTeamInfoDataById(data) {
    $("#delId").val(data.id);
    $("#tips").html("是否删除本条调组记录?");
}

// 弹出修改模态框
function del(id) {
    getTransferTeamInfoById(id);
}
// 执行删除
function doDel() {
    let data = {id: $("#delId").val()}
    let result = jsonPost("/stu/teamInfo/delTeamInfo", data);
    console.log(result)
    if (result.data.data == 1) {
        $(".right").load("/html/team/team-info.html");
    }
}

// 获取多选框选择的登录记录
function getCheckTimeInfos() {
    let timeInfos = [];
    $("[name='checkOne']:checkbox").each(function(i){
        if ($(this).prop("checked") == true){
            timeInfos.push(parseInt($(this).val()));
        }
    })
    timeInfos = JSON.stringify(timeInfos);
    timeInfos = timeInfos.replace("[","").replace("]","");
    return timeInfos;
}
// 批量删除
function batchDeletion() {
    let timeInfos = getCheckTimeInfos();
    let data = {ids:timeInfos}
    let result = jsonPostParam("/stu/teamInfo/batchDeletion", data);
    console.log(result);
    if (result.data.data = "success"){
        $(".right").load("/html/team/team-info.html");
    }
}

// 查询点击事件
function select() {
    page("home");
}
// 清空点击事件
function clearAll() {
    $("input[ type='text']").val("");
    $("input[ type='date']").val("");
    $("#pageSize").val(10);
    $("#pageNum").val(1);
}